package com.example.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import lombok.val;

import java.util.Date;
import java.util.Map;
import java.util.Vector;

public class JwtUtils {

   private static String signKey = "helloword";
    public static Long time = 43200000L;


    //创建Jwt
    public static String generateJwt (Map<String,Object> datamap){

       String Jwt = Jwts.builder().addClaims(datamap)
                .signWith(SignatureAlgorithm.HS256 , signKey)   //编译格式 秘钥
                .setExpiration(new Date(System.currentTimeMillis() + time))    //令牌有效期
                .compact();

        return Jwt;
    }


    //效验Jwt

    public static Claims parseJwt(String Jwt){
        Claims claims  = Jwts.parser()
                .setSigningKey(signKey)  //编译秘钥
                .parseClaimsJws(Jwt)
                .getBody();
            return claims;

    }

}
